/*
 * @Author: dingyuwen ding_yuwen@163.com
 * @Date: 2023-01-11 11:20:54
 * @LastEditTime: 2023-09-05 10:05:13
 * @LastEditors: DingYuwen 43669762+DingYuwen@users.noreply.github.com
 * @Description:
 */

import { FC, ReactNode, Suspense, useEffect } from 'react';

import { CustomLoader as SuspenseLoading } from '@/common/components/NewLoading';
import { APP_NAME } from '@/config/constants';

interface PropsType {
  component: ReactNode | null;
  loading?: ReactNode | null;
  title?: string;
}
const LazyElement: FC<PropsType> = (props) => {
  const title = props.title;
  useEffect(() => {
    if (title) {
      // 动态修改页面title
      document.title = title || APP_NAME;
    }
  }, [title]);
  return (
    <Suspense fallback={props.loading ?? <SuspenseLoading />}>
      {props.component}
    </Suspense>
  );
};

export default LazyElement;
